/*********************************************************************
*
*   DigitalOutput.cpp - Digital output class
*
*   Copyright:
*       Software source code by Alex Morozov and Chris D. Locke is
*       licensed under a Creative Commons Attribution-Noncommercial-
*       Share Alike 3.0 United States License
*       (http://creativecommons.org/licenses/by-nc-sa/3.0/us/)
*
*********************************************************************/

#include "StdAfx.h"

#include "CppBot.h"
#include "DigitalOutput.h"

//#include "DigitalModule.h"

void DigitalOutput::InitDigitalOutput(UINT32 slot, UINT32 channel)
{
    m_channel = channel;
    m_slot    = slot;
    init_dio( slot, channel, true );
}

/**
 * Create an instance of a digital output.
 * Create a digital output given a channel. The default module is used.
 */
DigitalOutput::DigitalOutput(UINT32 channel)
{
    InitDigitalOutput( 4/*CDL GetDefaultDigitalModule()*/, channel );
}

/**
 * Create an instance of a digital output.
 * Create an instance of a digital output given a slot and channel.
 */
DigitalOutput::DigitalOutput( UINT32 slot, UINT32 channel )
{
    InitDigitalOutput( slot, channel );
}

/**
 * Free the resources associated with a digital output.
 */
DigitalOutput::~DigitalOutput( )
{
}

/**
 * Set the value of a digital output.
 * Set the value of a digital output to either one (true) or zero (false).
 */
void DigitalOutput::Set( UINT32 value )
{
    set_dio( m_slot, m_channel, value ? true : false );

}

/**
 * Output a single pulse on the digital output line.
 * Send a single pulse on the digital output line where the pulse diration is specified in seconds.
 * Maximum pulse length is 0.0016 seconds.
 * @param length The pulselength in seconds
 */
void DigitalOutput::Pulse( float length )
{
    //CDL TODO: tRioStatusCode localStatus = 0;
    //CDL TODO: m_module->Pulse(m_channel, (UINT8)(1e9 * length / (tDIO::readLoopTiming(&localStatus) * 25)));
}

/**
 * Determine if the pulse is still going.
 * Determine if a previously started pulse is still going.
 */
bool DigitalOutput::IsPulsing( )
{
    //CDL TODO: return m_module->IsPulsing(m_channel);
    return( false );
}
